package com.example.mylock;

import javax.swing.*;

/**
 * description: DeadLockDemo <br>
 * date: 2020/12/14 10:04 <br>
 *
 * @author: ZhangYixin <br>
 * version: 1.0 <br>
 */
public class DeadLockDemo {

    private static Object object1 = new Object();
    private static Object object2 = new Object();

    public static void main(String[] args) {
        JPasswordField jPasswordField = null;
        new Thread(()->{
            synchronized (object1){
                try {
                    System.out.println("线程A拿到obj1锁");
                    Thread.sleep(3000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (object2){
                    System.out.println("线程A拿到obj2锁");
                }
            }
        }).start();
        new Thread(()->{
            synchronized (object2){
                try {
                    System.out.println("线程B拿到obj2锁");
                    Thread.sleep(3000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (object1){
                    System.out.println("线程B拿到obj1锁");
                }
            }
        }).start();
    }

}
